/**
 * Button.java
 * 
 * Copyright (C) 2012 - Thibault BUREL
 * 
 * This file is part of MathDraft.
 *
 * MathDraft is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MathDraft is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MathDraft.  If not, see <http://www.gnu.org/licenses/>
 *  
 */
package drk.mathdraft.ihm;

import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JButton;

import org.scilab.forge.jlatexmath.TeXConstants;
import org.scilab.forge.jlatexmath.TeXFormula;
import org.scilab.forge.jlatexmath.TeXIcon;

public class EqButton extends JButton {
	
	private static final long serialVersionUID = 1L;
	
	protected TeXIcon icon;

	public EqButton(String s) {
		super();
		
		TeXFormula formula = new TeXFormula(s);
		
		this.icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 15);
		
		this.setMinimumSize
			(new Dimension(this.icon.getIconWidth(),
					       this.icon.getIconHeight()));
	}

	public void paint(Graphics g) {
		super.paint(g);
		
		icon.paintIcon(this, g, 
			(this.getWidth() - this.icon.getIconWidth()) / 2,
			(this.getHeight() - this.icon.getIconHeight()) / 2);
	}
}